import Vue from "vue";
import VueRouter from "vue-router";
import Home from "@/views/home/Home.vue";
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => console.log(err));
};
Vue.use(VueRouter);
const routes = [
  {
    path: "/home",
    name: "Home",
    component: Home,
    children: [
      // 流量切分
      {
        path: "/home/flowSegmentation",
        name: "flowSegmentation",
        component: () => import("@/views/home/flowSegmentation.vue"),
      },
    ],
  },
  // {
  //   path: "/about",
  //   name: "about",
  //   component: () => import("@/views/home/about.vue"),
  // },
];

const router = new VueRouter({
  routes,
});
// router.beforeEach(async (to, from, next) => {
//   console.log("to", to);
//   console.log("from", from);
//   console.log("router111111111111111111111111111", routes, router);

//   router.addRoute({
//     path: "/about",
//     name: "About",
//     component: () => import("@/views/home/about.vue"),
//   });
//   console.log("router22222222222222222222222", router);
//   next();
//   if (to.path == "/about") {
//     next();
//   }
// });
let isAddRouter = false;
router.beforeEach((to, from, next) => {
  if (!isAddRouter) {
    isAddRouter = true;
    router.addRoutes([
      {
        path: "/about",
        name: "About",
        component: () => import("@/views/home/about.vue"),
      },
    ]);
    next({ ...to, replace: true });
  } else {
    next();
  }
});
export default router;
